

import java.util.HashMap;
import java.util.Map;

public class UserSystem {
    private Map<String, String> userMap = new HashMap<>(); // 用户名和密码的映射表

    //初始化用户和密码
    public void neizhi(){
        userMap.put("wxs","123456");
        userMap.put("lgj","123456");
        userMap.put("ynw","123456");
        userMap.put("jly","123456");
    }


    public void register(String username, String password) {
        if (!userMap.containsKey(username)) { // 判断用户名是否已经被注册
            userMap.put(username, password);
            System.out.println("注册成功！");
        } else {
            System.out.println("该用户名已被注册，请重新输入！");
        }
    }

    public boolean login(String username, String password) {
        if (userMap.containsKey(username) && userMap.get(username).equals(password)) { // 判断用户名和密码是否匹配
            System.out.println("登录成功！");
            return true;
        } else {
            System.out.println("用户名或密码错误，请重新输入！");
            return false;
        }
    }

}
